package drawingObjects;

import java.awt.Graphics;
import java.awt.Point;

public class Triangle extends DrawingObject {

	private Point p1;
	private Point p2;
	private Point p3;
	
	public Triangle(){
		p1 = null;
		p2 = null;
		p3 = null;
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		if(p1 != null && p2 != null)
			g.drawLine(p1.x, p1.y, p2.x, p2.y);
		if(p3!=null){
			g.drawLine(p2.x, p2.y, p3.x, p3.y);
			g.drawLine(p3.x, p3.y, p1.x, p1.y);
		}
	}
	
	@Override
	public boolean commit() {
		return (p1 != null && p2 != null && p3 != null);
	}

	@Override
	public void start(Point p) {
		if(p1 == null){
			p1 = new Point(p);
		}
		else if(p2 == null){
			p2 = new Point(p);
		}
		else if(p3 == null){
			p3 = new Point(p);
		}
	}

	@Override
	public void step(Point p) {
		p2 = new Point(p);
	}

}
